/**
 * Created by kevin on 2017/01/08.
 *
 * UI层
 * 音乐icon
 */


var eosi = window.eosi || {};
this.eosi.website = this.eosi.website || {};

(function (window) {
    // the application


    function PopupLayer(type) {

        this.Container_constructor();
        if(type){
            this.type = type;
        }
        this.init();
        //console.log(this.father.targetWidth);

    }
    //PopupLayer.TYPE = "people";


    var p = createjs.extend(PopupLayer, createjs.Container);

    p.className = "PopupLayer";
    p.type;//0=单张图，1=背景图加前层
    //加载器
    p.loader;
    //配置
    p.config=[];
    //资源是否加载完毕
    p.resIsLoaded = false;

    // public methods:
    p.init = function () {
        this.loadRes();
        //console.log(this.className);
    }


    /*
     * 加载资源
     * */
    p.loadRes = function(){
        this.loader = new createjs.LoadQueue(true);
        this.loader.on("complete", this.loadComplete, this);
        this.loader.on("fileload", this.onLoaded, this);

        this.loader.loadManifest({src: BASE_PATH + "static/PopupLayerManifest.json?v="+version, callback: "loadPopupMediaGrid", type: "manifest"}, true, "");

    }
    /*
    * 资源加载
    * */
    p.onLoaded = function (evt){

        var item = evt.item;
        //console.log(item)
        this.config.push(item);


    }
    /*
     * 资源加载完毕
     * */
    p.loadComplete = function (evt){
        //console.log(this.config.length);
        this.resIsLoaded = true;


    }


    /*
     * 绘制popup
     * */
    p.createPopup = function(group_id){
        //console.log("popup")
        var real_id;
        var config=[];
        for(var i = 0 ; i < this.config.length ; i++){
            //console.log(this.config[i])
            if(this.config[i]['group_id'] == group_id){
                config.push(this.config[i]);
            }
        }
        if(config.length<=0){
            console.log("Has no popup named '"+group_id+"'");
            return;
        }
        /*switch (group_id){

        }
        real_id = group_id + "bg";*/
        var popup;
        //console.log(config)
        switch (config[0].pop_type){
            case "single_pic":
                popup = new eosi.website.PopupSinglePic(config);
                break;
            case "full_screen":
                popup = new eosi.website.PopupFullScreen(config,this.loader);
                //popup.loader = this.loader;
                //console.log(this.loader)
                break;
        }

        this.addChild(popup);




    }




    // add MyApp to myNameSpace
    window.eosi.website.PopupLayer = createjs.promote(PopupLayer, "Container");
//}());
}(window));





